//
//  PBHomeSettingCell.m
//  PBHomeDemo
//
//  Created by Playboy on 2017/12/31.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "PBHomeSettingCell.h"
#import "PBSettingCollectionViewCell.h"

static NSString * const kPBSettingCollectionViewCell = @"PBSettingCollectionViewCell";

@interface PBHomeSettingCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableDictionary *houseInfo;
@end

@implementation PBHomeSettingCell

- (NSMutableDictionary *)houseInfo {
    if (!_houseInfo) {
        _houseInfo = [[NSMutableDictionary alloc] init];
    }
    return _houseInfo;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self configure];
}

- (void)configure {
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:kPBSettingCollectionViewCell bundle:nil] forCellWithReuseIdentifier:kPBSettingCollectionViewCell];
}

- (void)refreshWithInfo:(NSDictionary *)houseInfo {
    for (NSInteger i = 0; i < houseInfo.count; i ++) {
        if ([[houseInfo allValues][i] integerValue] == 1) {
            if ([[houseInfo allKeys][i] isEqualToString:@"bed"]) {
                [self.houseInfo setValue:[houseInfo allValues][i] forKey:@"床"];
            }else if ([[houseInfo allKeys][i] isEqualToString:@"heater"]) {
                [self.houseInfo setValue:[houseInfo allValues][i] forKey:@"热水器"];
            }else if ([[houseInfo allKeys][i] isEqualToString:@"airCondition"]) {
                [self.houseInfo setValue:[houseInfo allValues][i] forKey:@"空调"];
            }else if ([[houseInfo allKeys][i] isEqualToString:@"desk"]) {
                [self.houseInfo setValue:[houseInfo allValues][i] forKey:@"阳台"];
            }else if ([[houseInfo allKeys][i] isEqualToString:@"wardrobe"]) {
                [self.houseInfo setValue:[houseInfo allValues][i] forKey:@"衣柜"];
            }else if ([[houseInfo allKeys][i] isEqualToString:@"washwheel"]) {
                [self.houseInfo setValue:[houseInfo allValues][i] forKey:@"洗衣机"];
            }else if ([[houseInfo allKeys][i] isEqualToString:@"microwaveOven"]) {
                [self.houseInfo setValue:[houseInfo allValues][i] forKey:@"微波炉"];
            }else if ([[houseInfo allKeys][i] isEqualToString:@"wifi"]) {
                [self.houseInfo setValue:[houseInfo allValues][i] forKey:@"wifi"];
            }
        }
    }
    NSLog(@"%@",self.houseInfo);
    [self.collectionView reloadData];
}

#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.houseInfo.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    PBSettingCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kPBSettingCollectionViewCell forIndexPath:indexPath];
    [cell refreshWithHouseInfo:self.houseInfo indexPath:indexPath];
    return cell;
}

#pragma mark - <UICollectionViewDelegateFlowLayout>
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(50, 50);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 1;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
